package com.lee.forum.mq.publisherconfig;

import lombok.RequiredArgsConstructor;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;

// 封装专门用来发送延迟消息的处理器
@RequiredArgsConstructor
public class DelayMessageProcessor implements MessagePostProcessor {

    private final int delay;

    @Override
    public Message postProcessMessage(Message message) throws AmqpException {
        message.getMessageProperties().setDelay(delay);
        return message;
    }
}
// 替代每次都要new：
//new MessagePostProcessor(){
//@Override
//public Message postProcessMessage(Message message)throws AmqpException{
//        // 延迟10秒
//        message.getMessageProperties().setDelay(5000);
//        return message;
//        }
//        }